package Ctr;
import model.*;
import DBLayer.DBConnection;
import DBLayer.DBStockLog;

public class CtrStockLog {
	
	public CtrStockLog(int productID, int employeeID, int amount) {	
		CtrEmployee ctre = new CtrEmployee();
		CtrProduct ctrp = new CtrProduct();
		Employee e = ctre.getEmployee(employeeID);
		
		ctrp.updateStockAmount(productID, amount);
		insertStockLog(amount, e, ctrp.getProduct(productID));
		CtrPurchase ctrpur = new CtrPurchase(productID);
		System.out.println("done");
	}
	
	public void insertStockLog(int amount , Employee emp, Product pro) {		
		StockLog sl = new StockLog(amount, emp, pro);
		DBStockLog dsl = new DBStockLog();
		System.out.println("Empnavn " + sl.getEmployee().getEmpName());
		try {
			DBConnection.startTransaction();
			dsl.insertStockLog(sl);
			DBConnection.commitTransaction();
		} 
		catch (Exception e) {
			e.printStackTrace();
			DBConnection.rollbackTransaction();
		}
	}
	
}
